import Controller from "./Controller";
import {Request,Response} from 'express';
import path from 'path'
import { exec } from 'child_process';
import Config from "../Config";

/**
 * 微信开发工具操作
 */
class WeiXinTool extends Controller
{
    constructor(req?:Request,res?:Response) {
        super(req,res);
    }

    /**
     * 打开工具
     */
    async open(Cache:any) {
        const tpl_id = Cache.get("tpl_id");
        const setting = await this.first("setting") as {weixin_tool_path:string}
        const Tpl = await this.first("tpl",{id: tpl_id}) as {dir:string} 
        exec(`${path.join(setting.weixin_tool_path,'cli')} open --project ${path.join(Config.data_dir,Tpl.dir,'dist','dev','mp-weixin')}`)
        this.response(200)
    }

}

export default WeiXinTool

